using System;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;

public class ToValue : MonoBehaviour
{
    public string propertyName;
    public float targetValue;
    public float duration;
    private Graphic img;
    private Renderer render;

    private Material mat;
    private void Awake()
    {
        img = GetComponent<Graphic>();
        render = GetComponent<Renderer>();
        if (img)
        {
            mat = new Material(img.material);
            img.material = mat;
        }
        else if (render)
        {
            mat = new Material(render.material);
            render.material = mat;
        }
        DOTween.To(() =>mat.GetFloat(propertyName), (v) =>
        {
            mat.SetFloat(propertyName, v);
        }, targetValue, duration);
    }
}
